﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.HtmlControls;
using System.Diagnostics;

namespace PlanB.ShareDove.ConferenceOrganization.Portal.BadExamples.BadWebPart
{
    /// <summary>
    /// A Bad WebPart Example
    /// </summary>
    [ToolboxItemAttribute(false)]
    public class BadWebPart : WebPart
    {
        /// <summary>
        /// Create Child Controls in bad webpart
        /// </summary>
        protected override void CreateChildControls()
        {
            try
            {
                HtmlTable table = new HtmlTable();
                table.Rows.Add(new HtmlTableRow());
                table.Rows[0].Cells.Add(new HtmlTableCell());

                string cities = "";
                SPList citiesList = SPContext.Current.Web.Lists["Cities list"];
                foreach (SPListItem cityItem in citiesList.Items)
                    cities += cityItem["City name"].ToString() + "<br />";

                table.Rows[0].Cells[0].InnerHtml = cities;

                this.Controls.Add(table);

                base.CreateChildControls();
            }
            catch (Exception ex)
            {
                Debug.Print(ex.Message);
            }
        }
    }
}
